/*************************************
Author: IDC
Purpose: To create an order on change 
         of Recurring Charge Value
requirement: #908 OOR Phase 2
*************************************/
trigger OOR_PreviousRecurringUpdate on Account (before update) {
    ID SFAOORAccountecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
    List<Account> AccountList = new List<Account>();
        for(Account Acc:Trigger.new){
           If(Acc.recordtypeId == SFAOORAccountecordTypeID){
            if(Acc.OwnerId != Trigger.OldMap.get(Acc.Id).OwnerId){
                Acc.OOR_Previous_Recurring_Charges__c = Trigger.OldMap.get(Acc.Id).Recurring_Charge__c;
                
            }
            if(Acc.Recurring_Charge__c != Trigger.OldMap.get(Acc.Id).Recurring_Charge__c && Trigger.OldMap.get(Acc.Id).Recurring_Charge__c != NULL){
                Acc.OOR_Previous_Recurring_Charges__c = Trigger.OldMap.get(Acc.Id).Recurring_Charge__c;
            //system.debug('@@@@@@@@@@@'+Acc.OOR_Previous_Recurring_Charges__c+Acc.Recurring_Charge__c);    
            }
            //system.debug('###########'+Acc.OOR_Previous_Recurring_Charges__c+Acc.Recurring_Charge__c);
            if(Acc.OOR_Previous_Recurring_Charges__c != Acc.Recurring_Charge__c && Acc.OOR_Previous_Recurring_Charges__c != NULL && Acc.Recurring_Charge__c != NULL && Acc.Recurring_Charge__c != Trigger.OldMap.get(Acc.Id).Recurring_Charge__c){
                AccountList.add(Acc);
            }
           }
        }
        If(AccountList.size()>0){
            OOR_CreateOppOnRecurringChange.CreateOrder(AccountList);
        }

}